#include "thread.h"
#include <stdio.h>
#include <assert.h>
#include <signal.h>
#include <sys/time.h>
#include <limits.h>

static void * threadfunc(void * arg)
{
  char *name = arg;
  printf("je suis le thread %p, lancé avec l'argument %s\n",
	 thread_self(), name);
  int i;
  for(i=0;i!=INT_MAX/2;i++);
  thread_exit(arg);
}

int main(int argc, char *argv[])
{
  thread_t thread[2];
  void *retval[2];
  int err;
  char s[2][12];
  int i;
  printf("main %p",thread_self());

  for(i=0;i<2;i++)
    {
      sprintf(s[i],"thread%d",i);
      err = thread_create(&thread[i], threadfunc, s[i]);
      assert(!err);
    }
  for(i=0;i<2;i++)
    {
      printf("le main join le thread%d",i);
      err = thread_join(thread[i], &retval[i]);
      printf("le thread %d a terminé en renvoyant '%s'\n",i,(char *)retval[i]);
    }
 
  return 0;
}
